< previous page page_301 next page >

Page 301
z0321-01.gif
Figure 10.24
Recursive relationships
among Sierpinski subcurves.
e10a6a0a59f035e870d90cca05b85fce.gif
        picCanvas.Line -Step(-dist, 0)
        SierpD depth - 1, dist
        picCanvas.Line -Step(-dist, -dist)
        SierpA depth - 1, dist
    End If
End Sub
In addition to the routines that draw each of the four basic curve types, the program needs a routine that uses the four to create the completed Sierpinski curve.
e10a6a0a59f035e870d90cca05b85fce.gif
' Draw the complete Sierpinski curve.
Private Sub Sierpinski(depth As Integer, dist As Single)
    SierpB depth, dist
    picCanvas.Line -Step(dist, dist)
    SierpC depth, dist
    picCanvas.Line -Step(dist, -dist)
    SierpD depth, dist
    picCanvas.Line -Step(-dist, -dist)
    SierpA depth, dist
    picCanvas.Line -Step(-dist, dist)
End Sub
Example program Sierp uses these recursive routines to draw Sierpinski curves. Be sure to test the program with relatively small levels of recursion (three or four) until you know how long the program takes on your computer.
Peano Curves
Figure 10.25 shows Peano curves of depths one, two, and three. Arrows on the level-one curve show the order in which the segments were drawn.
High-level Peano curves are made up of smaller curves appropriately scaled and rotated. Like the Hilbert curve code presented earlier, the Peano curve routine uses two variables, dx and dy, to indicate the direction in which it is drawing. When the routine recurses, it calls itself nine times with the dx and dy parameters scaled by a factor of one-third and switched around to produce an appropriately rotated curve.
Example program Peano uses the following code to draw Peano curves. You may want to step through the routine in the debugger a few times to see how dx and dy are switched to draw the correct curves.

 
< previous page page_301 next page >